package com.pri.chat.adapter;

import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.netease.nim.uikit.net.entity.KeFuEntity;
import com.netease.nimlib.sdk.msg.model.RecentContact;
import com.pri.chat.R;

import java.util.List;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

/**
 * 描述：添加类的描述
 *
 * @author
 * @time 2020/5/9
 */
public class KeFuMsgAdapter extends BaseQuickAdapter<List<KeFuEntity>, BaseViewHolder> {
    private OnAdapterClickListener mOnAdapterClickListener;
    public void setOnAdapterClickListener( OnAdapterClickListener listener) {
        mOnAdapterClickListener = listener;
    }
    public interface OnAdapterClickListener {

        void onAdapterClick(KeFuEntity kefuObj);
    }
    public KeFuMsgAdapter(int layoutResId, @Nullable List<List<KeFuEntity>> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, List<KeFuEntity> item) {
        RecyclerView rec_main = helper.getView(R.id.rec_main);
        View contentLinear = helper.getView(R.id.contentLinear);
        if(item.size()==1){
            helper.setText(R.id.content, item.get(0).getRemark());
            helper.setText(R.id.title,item.get(0).getTitle());
            rec_main.setVisibility(View.GONE);
            contentLinear.setVisibility(View.VISIBLE);
        }else{
            rec_main.setVisibility(View.VISIBLE);
            contentLinear.setVisibility(View.GONE);
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
            rec_main.setLayoutManager(linearLayoutManager);
            KeFuMsgDetailAdapter mAdapter = new KeFuMsgDetailAdapter(R.layout.item_kefu_msg_detail, item);
            rec_main.setAdapter(mAdapter);
            mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    if(mOnAdapterClickListener != null){
                        mOnAdapterClickListener.onAdapterClick(item.get(position));
                    }
                }
            });
        }
    }
}
